import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: 路由配置项
 *
 * hidden: true                     // 当设置 true 的时候该路由不会再侧边栏出现 如401，login等页面，或者如一些编辑页面/edit/1
 * alwaysShow: true                 // 当你一个路由下面的 children 声明的路由大于1个时，自动会变成嵌套的模式--如组件页面
 *                                  // 只有一个时，会将那个子路由当做根路由显示在侧边栏--如引导页面
 *                                  // 若你想不管路由下面的 children 声明的个数都显示你的根路由
 *                                  // 你可以设置 alwaysShow: true，这样它就会忽略之前定义的规则，一直显示根路由
 * redirect: noRedirect             // 当设置 noRedirect 的时候该路由在面包屑导航中不可被点击
 * name:'router-name'               // 设定路由的名字，一定要填写不然使用<keep-alive>时会出现各种问题
 * query: '{"id": 1, "name": "ry"}' // 访问路由的默认传递参数
 * roles: ['admin', 'common']       // 访问路由的角色权限
 * permissions: ['a:a:a', 'b:b:b']  // 访问路由的菜单权限
 * meta : {
    noCache: true                   // 如果设置为true，则不会被 <keep-alive> 缓存(默认 false)
    title: 'title'                  // 设置该路由在侧边栏和面包屑中展示的名字
    icon: 'svg-name'                // 设置该路由的图标，对应路径src/assets/icons/svg
    breadcrumb: false               // 如果设置为false，则不会在breadcrumb面包屑中显示
    activeMenu: '/system/user'      // 当路由设置了该属性，则会高亮相对应的侧边栏。
  }
 */

// 公共路由
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login'),
    hidden: true
  },
  {
    path: '/register',
    component: () => import('@/views/register'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error/401'),
    hidden: true
  },
  {
    path: '',
    component: Layout,
    redirect: '/datafile'
    // redirect: 'index',
    // children: [
    //   {
    //     path: 'index',
    //     component: () => import('@/views/index'),
    //     name: 'Index',
    //     meta: { title: '首页', icon: 'dashboard', affix: true }
    //   }
    // ]
  },
  {
    path: '/index',
    component: Layout,
    redirect: '/datafile'
  },
  {
    path: '/user',
    component: Layout,
    hidden: true,
    redirect: 'noredirect',
    children: [
      {
        path: 'profile',
        component: () => import('@/views/system/user/profile/index'),
        name: 'Profile',
        meta: { title: '个人中心', icon: 'user' }
      }
    ]
  },
  {
    path: '/material/customdetail',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '',
        component: () => import('@/views/business/material/customdetail'),
        name: 'Customdetail',
        meta: { title: '多种平均应力修正方法预测', activeMenu: '/material/customdetail' }
      }
    ]
  },
  {
    path: '/material/fkmdetail',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '',
        component: () => import('@/views/business/material/fkmdetail'),
        name: 'Fkmdetail',
        meta: { title: 'FKM', activeMenu: '/material/fkmdetail' }
      }
    ]
  },
  {
    path: '/material/dnvdetail',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '',
        component: () => import('@/views/business/material/dnvdetail'),
        name: 'Dnvdetail',
        meta: { title: 'DNVGL', activeMenu: '/material/dnvdetail' }
      }
    ]
  },
  {
    path: '/material/bsdetail',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '',
        component: () => import('@/views/business/material/bsdetail'),
        name: 'Bsdetail',
        meta: { title: 'BS7608', activeMenu: '/material/bsdetail' }
      }
    ]
  },
  {
    path: '/material/bs003',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '',
        component: () => import('@/views/business/material/bs003'),
        name: 'Bs003',
        meta: { title: 'bs7608_003数据寿命评估详情', activeMenu: '/material/bs003' }
      }
    ]
  },
  {
    path: '/material/bs004',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '',
        component: () => import('@/views/business/material/bs004'),
        name: 'Bs004',
        meta: { title: 'bs7608_004数据寿命评估详情', activeMenu: '/material/bs004' }
      }
    ]
  },
  {
    path: '/material/bs005',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '',
        component: () => import('@/views/business/material/bs005'),
        name: 'Bs005',
        meta: { title: 'bs7608_005数据寿命评估详情', activeMenu: '/material/bs005' }
      }
    ]
  },
  {
    path: '/material/dianh28',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '',
        component: () => import('@/views/business/material/dianh28'),
        name: 'Dianh28',
        meta: { title: '点焊结构疲劳寿命预测', activeMenu: '/material/dianh28' }
      }
    ]
  },
  {
    path: '/material/dlrx37',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '',
        component: () => import('@/views/business/material/dlrx37'),
        name: 'Dlrx37',
        meta: { title: '断裂韧性预测', activeMenu: '/material/dlrx37' }
      }
    ]
  },
  {
    path: '/material/dvs1608',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '',
        component: () => import('@/views/business/material/dvs1608'),
        name: 'Dvs1608',
        meta: { title: 'DVS1608', activeMenu: '/material/dvs1608' }
      }
    ]
  },
  {
    path: '/material/dvs160825',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '',
        component: () => import('@/views/business/material/dvs160825'),
        name: 'Dvs160825',
        meta: { title: 'dvs160825预测评估详情', activeMenu: '/material/dvs160825' }
      }
    ]
  },
  {
    path: '/material/dvs160826',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '',
        component: () => import('@/views/business/material/dvs160826'),
        name: 'Dvs160826',
        meta: { title: 'dvs160826预测评估详情', activeMenu: '/material/dvs160826' }
      }
    ]
  },
  {
    path: '/material/dvs161227',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '',
        component: () => import('@/views/business/material/dvs161227'),
        name: 'Dvs161227',
        meta: { title: 'DVS1612', activeMenu: '/material/dvs161227' }
      }
    ]
  },
  {
    path: '/material/eurocode9',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '',
        component: () => import('@/views/business/material/eurocode9'),
        name: 'Eurocode9',
        meta: { title: 'Eurocode9', activeMenu: '/material/eurocode9' }
      }
    ]
  },
  {
    path: '/material/eurocode3',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '',
        component: () => import('@/views/business/material/eurocode3'),
        name: 'Eurocode3',
        meta: { title: 'Eurocode3', activeMenu: '/material/eurocode3' }
      }
    ]
  },
  {
    path: '/material/iiw200829',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '',
        component: () => import('@/views/business/material/iiw200829'),
        name: 'Iiw200829',
        meta: { title: 'IIW2008焊接接头疲劳强度评价', activeMenu: '/material/iiw200829' }
      }
    ]
  },
  {
    path: '/material/iiw200830',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '',
        component: () => import('@/views/business/material/iiw200830'),
        name: 'Iiw200830',
        meta: { title: 'IIW2008表面裂纹结构剩余寿命预测', activeMenu: '/material/iiw200830' }
      }
    ]
  },
  {
    path: '/material/iiw200831',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '',
        component: () => import('@/views/business/material/iiw200831'),
        name: 'Iiw200831',
        meta: { title: 'IIW2008深埋裂纹结构剩余寿命预测', activeMenu: '/material/iiw200831' }
      }
    ]
  },
  {
    path: '/material/iiw200832',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '',
        component: () => import('@/views/business/material/iiw200832'),
        name: 'Iiw200832',
        meta: { title: 'IIW2008轴向内表面裂纹压力管道剩余寿命预测', activeMenu: '/material/iiw200832' }
      }
    ]
  },
  {
    path: '/material/jhf',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '',
        component: () => import('@/views/business/material/jhf'),
        name: 'Jhf',
        meta: { title: '角焊缝静强度评价', activeMenu: '/material/jhf' }
      }
    ]
  },
  {
    path: '/material/jhf33',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '',
        component: () => import('@/views/business/material/jhf33'),
        name: 'Jhf33',
        meta: { title: 'jhf33预测评估详情', activeMenu: '/material/jhf33' }
      }
    ]
  },
  {
    path: '/material/jhf34',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '',
        component: () => import('@/views/business/material/jhf34'),
        name: 'Jhf34',
        meta: { title: 'jhf34预测评估详情', activeMenu: '/material/jhf34' }
      }
    ]
  },
  {
    path: '/material/lwkzsl36',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '',
        component: () => import('@/views/business/material/lwkzsl36'),
        name: 'Lwkzsl36',
        meta: { title: '裂纹扩展速率预测', activeMenu: '/material/lwkzsl36' }
      }
    ]
  },
  {
    path: '/material/plqd35',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '',
        component: () => import('@/views/business/material/plqd35'),
        name: 'Plqd35',
        meta: { title: '疲劳强度优化', activeMenu: '/material/plqd35' }
      }
    ]
  },
  {
    path: '/material/pren',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '',
        component: () => import('@/views/business/material/pren'),
        name: 'Pren',
        meta: { title: 'prEN17149', activeMenu: '/material/pren' }
      }
    ]
  },
  {
    path: '/material/pren1714915',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '',
        component: () => import('@/views/business/material/pren1714915'),
        name: 'Pren1714915',
        meta: { title: 'pren1714915预测评估详情', activeMenu: '/material/pren1714915' }
      }
    ]
  },
  {
    path: '/material/pren1714916',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '',
        component: () => import('@/views/business/material/pren1714916'),
        name: 'Pren1714916',
        meta: { title: 'pren1714916预测评估详情', activeMenu: '/material/pren1714916' }
      }
    ]
  },
]

// 动态路由，基于用户权限动态去加载
export const dynamicRoutes = [
  {
    path: '/system/user-auth',
    component: Layout,
    hidden: true,
    permissions: ['system:user:edit'],
    children: [
      {
        path: 'role/:userId(\\d+)',
        component: () => import('@/views/system/user/authRole'),
        name: 'AuthRole',
        meta: { title: '分配角色', activeMenu: '/system/user' }
      }
    ]
  },
  {
    path: '/system/role-auth',
    component: Layout,
    hidden: true,
    permissions: ['system:role:edit'],
    children: [
      {
        path: 'user/:roleId(\\d+)',
        component: () => import('@/views/system/role/authUser'),
        name: 'AuthUser',
        meta: { title: '分配用户', activeMenu: '/system/role' }
      }
    ]
  },
  {
    path: '/system/dict-data',
    component: Layout,
    hidden: true,
    permissions: ['system:dict:list'],
    children: [
      {
        path: 'index/:dictId(\\d+)',
        component: () => import('@/views/system/dict/data'),
        name: 'Data',
        meta: { title: '字典数据', activeMenu: '/system/dict' }
      }
    ]
  },
  {
    path: '/monitor/job-log',
    component: Layout,
    hidden: true,
    permissions: ['monitor:job:list'],
    children: [
      {
        path: 'index/:jobId(\\d+)',
        component: () => import('@/views/monitor/job/log'),
        name: 'JobLog',
        meta: { title: '调度日志', activeMenu: '/monitor/job' }
      }
    ]
  },
  {
    path: '/tool/gen-edit',
    component: Layout,
    hidden: true,
    permissions: ['tool:gen:edit'],
    children: [
      {
        path: 'index/:tableId(\\d+)',
        component: () => import('@/views/tool/gen/editTable'),
        name: 'GenEdit',
        meta: { title: '修改生成配置', activeMenu: '/tool/gen' }
      }
    ]
  }
]

// 防止连续点击多次路由报错
let routerPush = Router.prototype.push;
let routerReplace = Router.prototype.replace;
// push
Router.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(err => err)
}
// replace
Router.prototype.replace = function push(location) {
  return routerReplace.call(this, location).catch(err => err)
}

export default new Router({
  mode: 'history', // 去掉url中的#
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})
